﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DAL;
using System.Text;

namespace PeisongWeb.buyer
{
    public partial class buyer_dynamicOrderItem : System.Web.UI.Page
    {
        protected int id
        {
            get
            {
                int tmp;
                try { tmp = Convert.ToInt32(ViewState["id"]); }
                catch { tmp = 0; }
                return tmp;
            }
            set
            { ViewState["id"] = value; }
        }

        protected int type
        {
            get
            {
                int tmp;
                try { tmp = Convert.ToInt32(ViewState["type"]); }
                catch { tmp = 0; }
                return tmp;
            }
            set
            { ViewState["type"] = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["orderid"] != null)
                {
                    if (Library.Number.IsIntPositive(Request.QueryString["orderid"]))
                    {
                        id = Convert.ToInt32(Request.QueryString["orderid"]);
                    }
                }

                if (id != 0)
                {
                    rptBind();
                    getDetails();
                }
                else
                {
                    Response.Redirect("buyer_dynamicOrderList.html");
                }

            }
        }
        void rptBind()
        {
            StringBuilder where = new StringBuilder();
            where.Append("1=1");
            where.AppendFormat(" AND orderId={0}", id);
            DataSet ds = logic.order.selectDynamicOrderItem(where.ToString(), "productId desc",200,1);
            rpt_list.DataSource = ds.Tables[1];
            rpt_list.DataBind();
        }

        void getDetails()
        {
             DataSet ds=logic.order.selectDynamicOrder("orderid=" + id, "orderid", 1, 1);
             if (ds.Tables.Count>0)
             {
                 if (ds.Tables[1].Rows.Count > 0)
                 {
                     DataRow dr = ds.Tables[1].Rows[0];
                     if (dr["status"].ToString() == "6")
                     {
                         lbl_orderNo.Text = string.Format("#{0}",id);
                     }
                     else
                     {
                         lbl_orderNo.Text = dr["orderNo"].ToString();
                     }
                     lbl_status.Text = dr["orderStatus"].ToString();
                     lbl_receiveUser.Text = dr["contact"].ToString();
                     lbl_receiveTel.Text = dr["contactMobile"].ToString() + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + dr["contactPhone"].ToString();
                     lbl_receiveAddress.Text = dr["areaName"].ToString() + dr["address"].ToString();
                     lbl_orderDt.Text = dr["orderDt"].ToString();
                     lbl_amount.Text = String.Format("{0:F2}", dr["amount"]);
                     lbl_receiveDt.Text = dr["receiveDt"].ToString();
                     lbl_orderNote.Text = dr["note"].ToString() + "&nbsp;";
                 }
             }
        }

    }
}
